package com.qf.controller;

import com.qf.pojo.Student;
import com.qf.service.StudentService;
import com.qf.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/updateStudent")
public class UpdateController extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        Student student = new Student();
        student.setId(Integer.valueOf(req.getParameter("id")));
        student.setSname(req.getParameter("sname"));
        student.setAge(Integer.valueOf(req.getParameter("age")));
        student.setSex(req.getParameter("sex"));
        student.setTel(req.getParameter("tel"));
        student.setEmail(req.getParameter("email"));
        student.setAdress(req.getParameter("adress"));


        StudentService studentService = new StudentServiceImpl();
        boolean isUpdate = studentService.updateStudent(student);
        if (isUpdate){
            resp.sendRedirect("/findAll");
        }
    }
}
